﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;

namespace common
{
    public class MailSendHelp
    {
        //需要参数化
        private static string smtpStr = "smtp.163.com";
        //private static string smtpStr = "smtp.sina.com";
        //private static string mailname ="sdrom2008@gmail.com";
        private static string mailname = "sdrom2013@163.com";
        //private static string mailname ="rrrxxxx@sina.com";
        private static string mailpwd = "showme";
        //private static string mailpwd = "showme";

        public static bool sendMail(MailMessage message)
        {
            System.Net.Mail.SmtpClient client = new SmtpClient(smtpStr);

            client.UseDefaultCredentials = false ;
            client.Credentials = new System.Net.NetworkCredential(mailname,mailpwd);
            client.EnableSsl = true;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;

            //MailAddress addressFrom = new MailAddress("sdrom2008@gmail.com", "张三");
            //MailAddress addressTo = new MailAddress("sdrom2008@qq.com", "张三");
            MailAddress addressFrom = new MailAddress("sdrom2013@163.com", "张三");
            MailAddress addressTo = new MailAddress("sdrom2008@qq.com", "张三");

            //MailMessage message = new MailMessage(addressFrom, addressTo);
            //message.Sender = new MailAddress("rrrxxxx@sina.com");
            //message.BodyEncoding = System.Text.Encoding.UTF8;
            //message.IsBodyHtml = true;
            //message.Body = "hi hello";
            //message.Subject = "test";
            message = new MailMessage(addressFrom, addressTo);
            message.Sender = new MailAddress("sdrom2013@163.com");
            message.BodyEncoding = System.Text.Encoding.UTF8;
            message.IsBodyHtml = true;
            message.Body = "hi hello";
            message.Subject = "test";
            bool flag = true;
            try
            {
                client.Send(message);
            }
            catch
            {
                flag = false;
            }
            return flag;
        }
    }
}
